<?php

/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */

/**
 * This file contains the XML_Feed and XML_Feed_Exception classes.
 *
 * PHP version 5
 *
 * This file is part of PEAR::XML_Feed.
 *
 * PEAR::XML_Feed is free software: you can redistribute it and/or modify it
 * under the terms of the GNU Lesser General Public License as published by the
 * Free Software Foundation, either version 3 of the License, or (at your
 * option) any later version.
 *
 * PEAR::XML_Feed is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
 * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
 * details.
 *
 * You should have received a copy of the GNU Lesser General Public License
 * along with PEAR::XML_Feed. If not, see <http://www.gnu.org/licenses/>.
 *
 * @package     XML_Feed
 * @category    XML
 * @author      Michael J. I. Jackson <mjijackson@gmail.com>
 * @copyright   2007-2008 Michael J. I. Jackson
 * @license     http://www.gnu.org/licenses/lgpl-3.0.txt GNU LGPL 3.0
 * @version     SVN: $Id: Feed.php 6 2008-06-30 04:40:59Z mjijackson $
 */

require_once 'PEAR/Exception.php';

/**
 * A class for generating various types of feeds including RSS and Atom.
 *
 * @package     XML_Feed
 * @category    XML
 * @author      Michael J. I. Jackson <mjijackson@gmail.com>
 */
class XML_Feed extends DOMDocument
{

    /**
     * Constructor.
     *
     * @access  public
     */
    public function __construct()
    {
        parent::__construct();
        $this->formatOutput = true;
    }

    /**
     * Appends a child node to this feed. If a documentElement node has already
     * been created, all children will automatically be appended to it.
     * Otherwise, the node will be appended to the document directly.
     *
     * @param   DOMNode     $node       The node to append
     * @return  DOMNode                 The appended node
     * @access  public
     */
    public function appendChild(DOMNode $node)
    {
        if ($this->documentElement) {
            return $this->documentElement->appendChild($node);
        } else {
            return parent::appendChild($node);
        }
    }

    /**
     * Converts this feed to an XML string.
     *
     * @return  string      The XML for this feed
     * @access  public
     */
    public function __toString()
    {
        return $this->saveXML();
    }

}

/**
 * The exception class for all XML_Feed exceptions.
 *
 * @package     XML_Feed
 * @category    XML
 * @author      Michael J. I. Jackson <mjijackson@gmail.com>
 */
class XML_Feed_Exception extends PEAR_Exception {}

?>
